package com.rfid.api;

import java.util.ArrayList;

public class ConfigStrParser {
    private ArrayList<CfgStrField> m_list = new ArrayList();

    public boolean Parse(String str) {
        String[] totalStr = str.split(";");
        for (int i = 0; i < totalStr.length; i++) {
            String[] fildCfg = totalStr[i].split("=");
            if (fildCfg.length == 2) {
                CfgStrField m_cfg = new CfgStrField();
                m_cfg.m_name = fildCfg[0];
                m_cfg.m_value = fildCfg[1];
                this.m_list.add(m_cfg);
            } else if (fildCfg.length == 1) {
                CfgStrField m_cfg = new CfgStrField();
                m_cfg.m_name = fildCfg[0];
                m_cfg.m_value = "";
                this.m_list.add(m_cfg);
            } else return false;
        }
        return true;
    }

    public boolean ParseByName(String nameStr, StringBuffer valStr) {
        for (int i = 0; i < this.m_list.size(); i++) {
            CfgStrField cfg = (CfgStrField) this.m_list.get(i);
            if (nameStr.equals(cfg.m_name)) {
                valStr.append(cfg.m_value);
                return true;
            }
        }
        return false;
    }
}
